<?php
ini_set("session.auto_start","true");
    if (strlen(session_id()) == 0)
        session_start();

include 'inc/conn.php';
$usr = $_REQUEST['txtusername'];
$pwd = $_REQUEST['txtpassword'];
$sql = "select * from ats_users where username='$usr' and password=password('$pwd')";
$result = @mysql_query($sql)
    or die(json_encode(array('msg' => 'Login failed 1: ' . $sql)));

$rescount = mysql_num_rows($result);
if ($result && $rescount > 0) {
    //logged in
    //if (!isset($_COOKIE["PHPSESSID"]))
    

    $_SESSION['islogin'] = 1;

    $isLogin = $_SESSION['islogin'];

    echo json_encode(array('success' => true, 'msg' => "Login success, welcome back [$usr]"));
} else {
    echo json_encode(array('success' => false, 'msg' => "Login failed for user [$usr]"));
}
?>